const { DECIMAL, INITIAL_ANSWER, devlopmentChains } = require("../helper-hardhat-config")

module.exports = async({getNamedAccounts, deployments}) => {

    //本地环境才部署mock合约
    if (devlopmentChains.includes("hardhat")) {
        //firstAccount在hardhat.config.js的namedAccounts定义
        const {firstAccount} = (await getNamedAccounts())
        const {deploy} = deployments

        //deploy MockV3Aggregator contract
        //from: 合约部署者
        //args：合约构造函数入参
        //log：是否打印日志
        await deploy("MockV3Aggregator", {
            from: firstAccount,
            args: [DECIMAL, INITIAL_ANSWER],
            log: true
        })
    } else {
        console.log("enviroment is not local, mock contract deployment is skipped...")
    }
    
}

module.exports.tags = ["all", "mock"]